package com.ztgf.sms.api.client.email;

import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.sms.models.bo.EmailInfoBO;
import com.ztgf.sms.models.bo.EmailSendBO;
import com.ztgf.sms.models.service.IEmailInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * author: chenyu.wang
 * date: 2020-05-23 17:50
 * Description:
 */
@RestController
@RequestMapping("/api/email")
@Slf4j
@Api(value = "EmailInfoApiController", tags = "邮件接口")
public class EmailInfoApiController {
    @DubboReference
    private IEmailInfoService emailInfoService;

    @ApiOperation(value = "发送验证码",notes = "发送验证码")
    @PostMapping(value = "/saveCaptcha")
    public Result saveCaptcha( EmailSendBO emailInfoBO){
        emailInfoService.saveCaptcha(emailInfoBO);
        return new Result<>();
    }

    @ApiOperation(value = "发送验证码(脱敏邮箱)",notes = "发送验证码(脱敏邮箱)")
    @PostMapping(value = "/sendCaptcha")
    public Result sendCaptcha( EmailSendBO emailInfoBO){
        emailInfoService.sendCaptcha(emailInfoBO);
        return new Result<>();
    }

    @ApiOperation(value = "验证验证码",notes = "验证验证码")
    @PostMapping(value = "/getCaptcha")
    public Result getCaptcha( EmailSendBO emailInfoBO){
        boolean flag = emailInfoService.getCaptcha(emailInfoBO);

        if (flag){
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL);
        }
    }

    @ApiOperation(value = "发送激活邮件",notes = "发送激活邮件")
    @PostMapping(value = "/sendActiveEail")
    public Result sendActiveEail( EmailSendBO emailInfoBO){
        emailInfoService.sendActiveEail(emailInfoBO);
        return new Result<>();
    }
}
